﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

namespace JumpBall_2
{
    public class BallControll : MonoBehaviour
    {
        public float jumpHeight;            //跳跃高度
        public GameObject Canvas;           //画布游戏对象

        void Start()
        {

        }


        //重力加速
        public void Boost()
        {
            var rigidBody = GetComponent<Rigidbody>();
            rigidBody.velocity = new Vector3(0, -jumpHeight, 0);
        }


        //弹跳
        public void Bouce()
        {
            var rigidBody = GetComponent<Rigidbody>();
            rigidBody.velocity = new Vector3(0, jumpHeight, 0);
        }


        //碰撞
        private void OnCollisionEnter(Collision collision)
        {
            if (collision.gameObject.tag == "Respawn")
            {
                Bouce();
                ExecuteEvents.Execute<IMessage>(Canvas, null, (IMessage message, BaseEventData baseEventData) => message.Message1(1));
            }
        }

    }
}